﻿@using GlobalResources
@using Microsoft.Azure.IoTSuite.Connectedfactory.WebApp.Contoso
@using Microsoft.Azure.IoTSuite.Connectedfactory.WebApp.Models;

@model DashboardModel

<div class="dashboard_alerts_container_header row">
    <p class="dashboard_alerts_container_header_text overflow">@Strings.AlertsContainerHeader</p>
    <div class="dashboard_alerts_container_header_filter" hidden>v</div>
    <a id="allIconAlert" class="dashboard_alerts_container_header_text_glyph" href="#" onclick="openFilterAlertsContextPanel();" role="button">
        <img class="dashboard_children_container_header_filter" aria-label="filter" src="/Content/img/filter.svg">
        @Strings.NoFilterApplied
    </a>
    <p id="filterIconAlert" class="dashboard_alerts_container_header_text_glyph" hidden>
        <a id="openFromFilteredAlert" href="javascript:openFilterAlertsContextPanel();"><img class="dashboard_children_container_header_filter" src="/Content/img/filter.svg"></a>
    </p>
</div>
<div class="dashboard-padding"></div>
<table>
    <div id="alertsListContainer" class="dashboard_alerts_list_container scrollbar-inner scroll_only_y row" role="grid" aria-rowcount="@Model.Alerts.Count()">
        <div id="dashboardAlertsList" class="col-xs-12">
            @foreach (var alert in Model.Alerts)
            {
                var alertStatusClass = "";
                if (alert.Status == ContosoAlertStatus.AlertStatusAcknowledged)
                {
                    alertStatusClass = "alert_status_acknowledged";
                }
                else
                {
                    alertStatusClass = "alert_status_active";
                }
                var alertDescription = Strings.AlertDetailsUnknown;
                alertDescription = ContosoAlert.GetAlertCauseDescription(alert.Cause);
                <div role="row">
                    <div class="dashboard_alerts_listitem_container @alertStatusClass row" role="gridcell" onclick="openContextPanelFromAlert(@alert.AlertId)" onkeydown="if (event.keyCode == 13)openContextPanelFromAlert(@alert.AlertId)" tabindex="0">
                        <div class="dashboard_alerts_listitem_source overflow row">@alertDescription</div>
                        <div class="dashboard_alerts_listitem_source_details_container row">
                            <div class="dashboard_alerts_listitem_source_details overflow col-xs-7">
                                @{ int i = 0;}
                                @foreach (var detail in alert.TopologyDetails)
                                {
                                    if (detail != null)
                                    {
                                        if (i++ != 0)
                                        {
                                            <span>, </span>
                                        }
                                        <span class="dashboard_alerts_details@(i)">@detail</span>
                                    }
                                }
                            </div>
                            <div class="dashboard_alerts_listitem_source_details_time overflow col-xs-5">@alert.UxTime</div>
                        </div>
                    </div>
                </div>
            }
        </div>
    </div>
</table>
